package org.xs.object.utils;

import lombok.Data;
import org.springframework.context.annotation.Scope;
import org.xs.object.dao.class_table.Meta;

import java.io.Serializable;

@Data
@Scope("prototype")
public class R<T> implements Serializable {
    private Integer code;
    private String msg;
    //Meta
    //private Meta meta;
    private T data;
//    private String next;

    private R() {
    }

    public static <T> R<T> ok(T data) {
        R<T> r = new R<>();
        r.setCode(ResponseEnum.SUCCESS.getCode());
        r.setMsg(ResponseEnum.SUCCESS.getMag());
        r.setData(data);
        return r;
    }

//    public static <T> R<T> ok(T data) {
//        R<T> r = new R<>();
//        r.setCode(ResponseEnum.SUCCESS.getCode());
//        r.setMsg(ResponseEnum.SUCCESS.getMag());
//        r.setData(data);
//        return r;
//    }
    public static <T> R<T> ok(T data,Meta meta,String next) {
        R<T> r = new R<>();
        r.setCode(ResponseEnum.SUCCESS.getCode());
        r.setMsg(ResponseEnum.SUCCESS.getMag());
        r.setData(data);
        //r.setMeta(meta);
        return r;
    }

    public static <T> R<T> ok(){
        R<T> r = new R<>();
        r.setCode(ResponseEnum.SUCCESS.getCode());
        r.setMsg(ResponseEnum.SUCCESS.getMag());
        return r;
    }
    public static <T> R<T> error(ResponseEnum  data) {
        R<T> r = new R<>();
        r.setCode(data.getCode());
        r.setMsg(data.getMag());
        r.setData(null);
        return r;
    }


}
